<?	/*
	// File:	uw-imap.wcp.phps
	// Purpose:	UW-IMAP user manipulation
	// Author:	Felix <webmaster@can-host.com>
	*/


// Handle user manipulation
if ($type == "user") {
	// Create User :: expect *
	if ($data['action'] == "create") {
		
		// Create UW-IMAP Mailbox dir 
		$uwpath = $cfg['uwimapdir']."/".$data['username'];
		mkdir($uwpath, 0777);
		chmod($uwpath, 0777);
		chown($uwpath, $data['username']);
		chgrp($uwpath, "g".$data['id']);
		// Now create a link from mailspool to INBOX (UW-IMAP can't snarf in BlackBoxMode)
		symlink($cfg['mail_spool']."/".$data['username'], $uwpath."/INBOX");
		chown($uwpath."/INBOX", $data['username']);
		chgrp($uwpath."/INBOX", "g".$data['id']);
	}
	
	// Update User :: expect *
	if ($data['action'] == "update") {
		
		// if username changed, rename UW-IMAP dir
		if ($data['username'] != $data['username1']) {
			$olduwpath = $cfg['uwimapdir']."/".$data['username1'];
			$newuwpath = $cfg['uwimapdir']."/".$data['username'];
			rename($olduwpath,$newuwpath);
		}
	}
	
	// Remove User :: expect username
	if ($data['action'] == "remove") {

		// Remove UW-IMAP dir
		$uwpath = $cfg['uwimapdir']."/".$data['username'];
		if (is_dir($uwpath) AND $data['username'])
			exec($cfg['prog']['rm']." -rf $uwpath");
	}
}
?>
